<?php


use Biz\model\activity\BizProjectModel;
use Biz\model\activity\BizProjectResponsibilityModel;

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';


echo <<<CODE
======== 参数列表 =========
cache 查看所有缓存
init 初始化缓存
======== end =========
CODE, PHP_EOL;

$action = $argv[1] ?? '';
$p = $argv[2] ?? 1;
BizProjectModel::action(function () {


$arr = [
["九牧", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022076", "家宅融智", "九牧大咖项目", "198180", "2022-06-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-06-01 ~ 2022-12-31", "请补充", "禹兆丰", "蔡露", "李少龙", "执行中",    ],
["Hizero", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022038", "家宅融智", "Hizero仿生洗地机2022年新品推广", "1000000", "2022-05-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-05-01 ~ 2022-12-31", "请补充", "李桢", "蔡露", "李少龙", "执行中",    ],
["米家", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2021153-10", "家宅融智", "米家生态链-热水器+香氛机+鱼缸", "93000", "2022-11-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-11-01 ~ 2022-12-31", "请补充", "李桢", "蔡露", "李少龙", "执行中",    ],
["萨米特", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022056", "家宅融智", "萨米特2022半年口碑合作", "714000", "2022-05-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-05-01 ~ 2022-12-31", "请补充", "卢雨晴", "孙园园", "李晓洁", "执行中",    ],
["萨米特", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022072", "家宅融智", "萨米特年框追加-设计理想家", "150000", "2022-05-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-05-01 ~ 2022-12-31", "请补充", "卢雨晴", "孙园园", "李晓洁", "执行中",    ],
["卡萨帝", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022057", "家宅融智", "2022年卡萨帝冰箱项目", "809200", "2022-03-01 ~ 2022-06-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-03-01 ~ 2022-06-30", "请补充", "李晴", "蔡露", "李晓洁", "执行中",    ],
["百隆", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022082", "家宅融智", "百隆五金KOL长续合作", "506200", "2022-07-01 ~ 2022-10-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-07-01 ~ 2022-10-31", "请补充", "袁圆", "路思浓", "李晓洁", "执行中",    ],
["爱格", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022109", "家宅融智", "爱格设计师效果图合作", "80000", "2022-09-01 ~ 2022-11-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-09-01 ~ 2022-11-30", "请补充", "袁圆", "路思浓", "陈慧娴", "执行中",    ],
["梦百合", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022086", "家宅融智", "2022梦百合合作项目", "235000", "2022-10-01 ~ 2023-05-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2023-05-31", "请补充", "李桢", "路思浓", "陈慧娴", "执行中",    ],
["威能", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022155", "家宅融智", "威能10-12月项目", "680200", "2022-10-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2022-12-31", "请补充", "李晴", "路思浓", "李晓洁", "执行中",    ],
["科勒", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022102", "家宅融智", "科勒水乐章花洒项目", "200000", "2022-10-01 ~ 2022-11-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2022-11-30", "请补充", "李桢", "露思浓", "胡卫卫", "执行中",    ],
["科勒", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022099", "家宅融智", "科勒浴室柜&马桶&淋浴房项目", "900000", "2022-10-01 ~ 2022-11-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2022-11-30", "请补充", "李桢", "露思浓", "胡卫卫", "执行中",    ],
["科勒", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022174", "融智上海", "科勒PVD&入墙水龙头达人合作项目", "90980", "2022-12-01 ~ 2023-03-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2023-03-31", "请补充", "李桢", "露思浓", "胡卫卫", "执行中",    ],
["东鹏", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2021121", "家宅融智", "东鹏岩板推广·三棱镜项目", "1450000", "2021-08-01 ~ 2023-04-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2021-08-01 ~ 2023-04-30", "请补充", "禹兆丰", "蔡露", "胡卫卫", "执行中",    ],
["卡萨帝", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022159", "家宅融智", "卡萨帝12月广州设计周合作", "400000", "2022-11-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-11-01 ~ 2022-12-31", "请补充", "李晴", "杨美婷", "李晓洁", "执行中",    ],
["安吉尔", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2021161", "家宅一生", "安吉尔设计师项目", "50000", "2022-10-01 ~ 2022-11-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2022-11-30", "请补充", "禹兆丰", "路思浓", "李晓洁", "执行中",    ],
["德尔", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022153", "家宅融智", "德尔Q4-Q2项目", "550000", "2022-10-01 ~ 2023-06-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2023-06-30", "请补充", "李晴", "路思浓", "李晓洁", "执行中",    ],
["日立", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022043", "家宅融智", "日立中央空调2022年合作", "405000", "2022-10-01 ~ 2023-08-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-10-01 ~ 2023-08-31", "请补充", "李桢", "路思浓", "李晓洁", "执行中",    ],
["好好住", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "内部项目无编号", "家宅融智", "上海开业酒会", "0", "2022-11-01 ~ 2022-11-29", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-11-01 ~ 2022-11-29", "请补充", "卢雨晴", "", "越会会", "执行中",    ],
["能率", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022171", "融智上海", "2022 能率合作", "50000", "2022-12-01 ~ 2023-02-28", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2023-02-28", "请补充", "段柯彤", "杨美婷", "李晓洁", "执行中",    ],
["卡萨帝", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022057", "家宅融智", "卡萨帝冰箱12月", "566000", "2022-12-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2022-12-31", "请补充", "李晴", "蔡露", "李晓洁", "执行中",    ],
["世净", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022169", "家宅融智", "超级补贴日二期", "100000", "2022-11-01 ~ 2022-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-11-01 ~ 2022-12-31", "请补充", "大禹", "路思浓", "越会会", "执行中",    ],
["华为", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022179", "家宅融智", "全屋智能口碑合作", "200000", "2022-12-01 ~ 2023-02-28", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2023-02-28", "请补充", "杨笑平", "杨美婷", "越会会", "执行中",    ],
["COLMO", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022178", "家宅融智", "冯老板视频合作", "169600", "2022-09-01 ~ 2023-07-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-09-01 ~ 2023-07-31", "请补充", "卢雨晴", "杨美婷", "越会会", "执行中",    ],
["联塑", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022170", "家宅融智", "2023年达人口碑合作", "60800", "2022-12-01 ~ 2023-12-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2023-12-31", "请补充", "禹兆丰", "蔡露", "越会会", "执行中",    ],
["三星", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022177", "家宅融智", "三星电视追加资源包", "290000", "2022-12-01 ~ 2023-03-31", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-12-01 ~ 2023-03-31", "请补充", "都郁", "杨美婷", "陈慧娴,吴聪祥", "执行中",    ],
["杜拉维特", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022074", "家宅融智", "杜拉维特2022年Future项目合作", "1000000", "2022-08-01 ~ 2023-06-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2022-08-01 ~ 2023-06-30", "请补充", "李帧", "路思浓", "李少龙", "执行中",    ],
["滨特尔", "家用电器 - 电视", "请补充合作产品", "新客户", "华东", "安徽", "A3", "确认下单", "RZGG2022165-1", "家宅融智", "滨特尔年框合作1（65w大标签）", "650000", "2023-02-01 ~ 2023-04-30", "直客", "请补充签约公司名称", "22年未执行完毕项目，无需上传项目资料", "请补充", "2023-02-01 ~ 2023-04-30", "请补充", "袁圆", "杨美婷", "王晓雨,李少龙", "执行中",    ],
];

$addArr = [
    ['2022-06-16','王薇,罗丽娜','李傲'],
    ['2022-05-26','王薇,罗丽娜','李傲'],
    ['2022-12-26','王薇,罗丽娜','李傲'],
    ['2022-04-20','王薇,罗丽娜','李傲'],
    ['2022-06-14','王薇,罗丽娜','李傲'],
    ['2022-12-01','王薇,罗丽娜','李傲'],
    ['2022-07-21','王薇,罗丽娜','李傲'],
    ['2022-09-05','王薇,罗丽娜','李傲'],
    ['2022-09-23','王薇,罗丽娜','李傲'],
    ['2022-10-18','王薇,罗丽娜','李傲'],
    ['2022-09-19','王薇,罗丽娜','李傲'],
    ['2022-09-22','王薇,罗丽娜','李傲'],
    ['2022-12-16','王薇,张小玉','李傲'],
    ['2021-08-23','王薇,罗丽娜','李傲'],
    ['2022-12-02','王薇,罗丽娜','李傲'],
    ['2022-10-24','王薇,张小玉','李傲'],
    ['2022-10-24','王薇,罗丽娜','李傲'],
    ['2022-10-27','王薇,罗丽娜','李傲'],
    ['2022-11-07','王薇,罗丽娜','李傲'],
    ['2022-12-13','王薇,张小玉','李傲'],
    ['2022-12-02','王薇,罗丽娜','李傲'],
    ['2022-11-24','王薇,罗丽娜','李傲'],
    ['2022-12-29','王薇,罗丽娜','李傲'],
    ['2022-03-10','王薇,罗丽娜','李傲'],
    ['2022-12-29','王薇,罗丽娜','李傲'],
    ['2022-11-30','王薇,罗丽娜','李傲'],
    ['2022-06-08','王薇,罗丽娜','李傲'],
    ['2023-01-06','王薇,罗丽娜','李傲'],
];

$customerName = \Biz\model\activity\BizProjectCustomerModel::adminNameOptions();
$customerName = array_flip($customerName);
$categoryMap = [
    "家用电器 - 电视" => '9'
];
$project_subject = array_flip(\Biz\service\activity\project\BizProjectProject::PROJECT_SUBJECT_MAP);
$project_company_type = array_flip(\Biz\service\activity\project\BizProjectProject::COMPANY_TYPE_MAP);
$nameMap = [
    '禹兆丰' => 'yuzhaofeng',
    '蔡露' => 'cailu',
    '李少龙' => 'lishaolong',
    '李桢' => 'lizhen',
    '卢雨晴' => 'luyuqing',
    '孙园园' => 'sunyuanyuan',
    '李晓洁' => 'lixiaojie',
    '李晴' => 'liqing',
    '袁圆' => 'yuanyuan',
    '路思浓' => 'lusinong',
    '陈慧娴' => 'chenhuixian',
    '露思浓' => 'lusinong',
    '胡卫卫' => 'huweiwei',
    '杨美婷' => 'yangmeiting',
    '越会会' => 'yuehuihui',
    '段柯彤' => 'duanketong',
    '大禹' => 'yuzhaofeng',
    '杨笑平' => 'yangxiaoping',
    '都郁' => 'duyu',
    '吴聪祥' => 'wucongxiang',
    '李帧' => 'cailu',
    '王晓雨' => 'wangxiaoyu',
    '李傲' => 'liao',
    '王薇' => 'verawang',
    '罗丽娜' => 'luolina',
    '张小玉' => 'zhangxiaoyu',
];

$all = [];
foreach ($arr as $k => $row) {
    $customer_name = $customerName[$row[0]] ?? '';
    $customer_category = $categoryMap[$row[1]] ?? '';
    $projectDate = explode("~", $row[12]);
    $projectContractDate = explode("~", $row[17]);
    $project_contract = json_encode([['content' => trim($row[16]), 'kpi' => trim($row[18]), 'online_date_start' => trim($projectContractDate[0]), 'online_date_end' => trim($projectContractDate[1])]], JSON_UNESCAPED_UNICODE);
//    if (!strlen($customer_name)) continue;
    $addData = [
        'created_at' => $addArr[$k][0],
        'customer_name' => $customer_name,
        'customer_category' => $customer_category,
        'customer_product' => trim($row[2]),
        'customer_type' => '0',
        'customer_area' => '0',
        'customer_area_code' => '340300',
        'customer_level' => '0',
        'project_type' => '1',
        'project_no' => trim($row[8]),
        'project_subject' => $project_subject[$row[9]],
        'project_name' => trim($row[10]),
        'project_money' => trim($row[11]),
        'project_start_date' => trim($projectDate[0]),
        'project_end_date' => trim($projectDate[1]),
        'project_company_type' => $project_company_type[$row[13]],
        'project_company_name' => trim($row[14]),
        'project_external_link' => trim($row[15]),
        'project_contract' => $project_contract,
        'process_state' => '1',
    ];
    $rs = BizProjectModel::addData($addData);
    if (!$rs) throw new Exception('商业项目主表保存失败');
    $project_id = BizProjectModel::id();
    $responsible = [
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_SELLER => $row[19],
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_MEDIUM => $row[20],
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_PM => $row[21],
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_OWNER => $row[19],
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_LEGAL => $addArr[$k][2],
        BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_FINANCE => $addArr[$k][1],
    ];
    foreach ($responsible as $key => $v) {
        $adminArr = $v ? explode(',', $v) : [];
        foreach ($adminArr as $admin_id) {
            $all[$admin_id] = $admin_id;
            if (isset($nameMap[$admin_id])) {
                BizProjectResponsibilityModel::addData(['project_id' => $project_id, 'type' => $key, 'admin_id' => $nameMap[$admin_id]]);
            }
        }
    }
}
    var_dump($all);
//throw new \Exception("over");
});